package JDBC_Test.park;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class JDBCUtil {
	private static ResourceBundle rb = ResourceBundle.getBundle("JDBC_Test.park.jdbc");
	
	private static String className = rb.getString("driver");
	private static String url = rb.getString("url");
	private static String user = rb.getString("user");
	private static String password = rb.getString("password");
	
	
	static {
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Connection getConnection() throws SQLException {
		return DriverManager.getConnection(url, user, password);
	}
	
	public static void close(Connection connection,Statement st,PreparedStatement ps) throws SQLException {
		if(connection!=null) {
			connection.close();
			connection = null;
		}
		if(st!=null) {
			st.close();
			st = null;
		}
		if(ps!=null) {
			ps.close();
			ps = null;
		}
		
	}
	
	private JDBCUtil() {
		// TODO Auto-generated constructor stub
	}
}
